import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //或者定义类实现Callable接口
        Callable<String> stringCallable = () -> {
            System.out.println("okl");
            return "1024";
        };

        FutureTask<String> stringFutureTask = new FutureTask<>(stringCallable);
        new Thread(stringFutureTask, "a").start();
        String s = stringFutureTask.get();
        System.out.println(s);

        Threads threads = new Threads();
        FutureTask<String> stringFutureTask1 = new FutureTask<String>(threads);
        new Thread(stringFutureTask1, "a").start();
        System.out.println(stringFutureTask1.get());

    }

}

class Threads implements Callable {

    @Override
    public Object call() throws Exception {
        System.out.println("okl");
        return "1024";
    }
}
